home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / afloat.zip / FLOAT2.C < prev    next >
Text File  |  1988-03-16  |  1KB  |  34 lines

  1. /* float2.c -- sample program showing the use of float.lib and
  2.    tinylib.lib; code turns out to be more than 10 times smaller
  3.    than comparable program using the standard library's printf
  4.    and usual (double-precision) floating point math, and is
  5.    about 5-6 times faster; note also that tinylib has clock(),
  6.    which, as an ANSI C function should have been included with
  7.    Turbo C, but wasn't */
  8.  
  9. #include "float.h"
  10. #include "tinylib.h"
  11.  
  12. main()
  13. {
  14.     char string [80];
  15.     int i;
  16.     long mark;
  17.     float f, increment = .0001, time_passed, eighteen_point_five = 18.5;
  18.  
  19.         putstr ("enter float: ");
  20.     gets (string);
  21.     atoflt (string, &f);
  22.         mark = clock();
  23.         for (i = 0; i < 10000; i++)
  24.         fadd (&f, &increment, &f);
  25.     ltof (clock() - mark, &time_passed);
  26.     fdivide (&time_passed, &eighteen_point_five, &time_passed);
  27.     ftoa (&time_passed, string, 4);
  28.         putstr ("time in seconds for 10000 loops: ");
  29.     putstr (string);
  30.     ftoa (&f, string, 6);
  31.         putstr ("\n\rresult: ");
  32.     putstr (string);
  33. }
  34.